﻿<UserControl x:Class="cmdr.Editor.Views.MidiEditor"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
             xmlns:converters="clr-namespace:cmdr.Editor.Converters"
             xmlns:ddButton="clr-namespace:cmdr.WpfControls.DropDownButton;assembly=cmdr.WpfControls"
             mc:Ignorable="d" 
             d:DesignHeight="120" d:DesignWidth="300">
    <UserControl.Resources>
        <ResourceDictionary>
            <BooleanToVisibilityConverter x:Key="boolToVisConverter"/>
            <converters:InverseBooleanConverter x:Key="invBoolConverter"/>
        </ResourceDictionary>
    </UserControl.Resources>
    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="*"/>
            <RowDefinition Height="Auto"/>
        </Grid.RowDefinitions>
        
        <StackPanel Margin="5,0,5,0" Visibility="{Binding CanOverrideFactoryMap, Converter={StaticResource boolToVisConverter}}" Orientation="Horizontal">
            <CheckBox VerticalAlignment="Center" IsThreeState="True" IsChecked="{Binding OverrideFactoryMap}"/>
            <Label VerticalAlignment="Center" Margin="3,0,0,0">Override Factory Map</Label>
        </StackPanel>
        
        <Grid Grid.Row="1" IsEnabled="{Binding LearnMode, Mode=OneWay, Converter={StaticResource invBoolConverter}}">
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="Auto"/>
                <ColumnDefinition/>
            </Grid.ColumnDefinitions>
            
            <StackPanel Grid.Column="0" Orientation="Vertical" Visibility="{Binding IsGenericMidi, Mode=OneWay, Converter={StaticResource boolToVisConverter}}">
                <Label>Channel:</Label>
                <Grid>
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition/>
                        <ColumnDefinition Width="Auto"/>
                    </Grid.ColumnDefinitions>
                    
                    <Border BorderThickness="1,1,0,1" BorderBrush="LightGray" Height="25" Width="55">
                        <TextBlock Text="{Binding ChannelString, Mode=OneWay}" FontStyle="Italic" VerticalAlignment="Center" Padding="5,0,0,0" />
                    </Border>

                    <ddButton:DropDownButton Grid.Column="1" Content="Select" Width="Auto" 
                                             MenuPlacement="Left"
                                             Command="{Binding SelectChannelCommand, Mode=OneTime}" 
                                             ItemsSource="{Binding ChannelsMenu, Mode=OneTime}" />
                </Grid>
            </StackPanel>

            <StackPanel Grid.Column="1" Orientation="Vertical" Margin="5,0,0,0">
                <Label>Note:</Label>
                <Grid>
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition/>
                        <ColumnDefinition Width="Auto"/>
                    </Grid.ColumnDefinitions>
                    <Border BorderThickness="1,1,0,1" BorderBrush="LightGray" Height="25">
                        <TextBlock Text="{Binding NoteString, Mode=OneWay}" FontStyle="Italic" VerticalAlignment="Center" Padding="5,0,0,0" />
                    </Border>
                    <ddButton:DropDownButton Grid.Column="1" Content="Select" Width="Auto" 
                                             MenuPlacement="Left"
                                             Command="{Binding SelectNoteCommand, Mode=OneTime}" 
                                             ItemsSource="{Binding NotesMenu, Mode=OneTime}" />
                </Grid>
            </StackPanel>
        </Grid>
        
        <StackPanel Grid.Row="2" Orientation="Horizontal" HorizontalAlignment="Right" Height="30">
            <StackPanel Orientation="Horizontal" Visibility="{Binding IsGenericMidi, Mode=OneWay, Converter={StaticResource boolToVisConverter}}">
                <ddButton:DropDownButton Content="&#xFF0B;/&#xFF0D;" Height="20" Width="50" Margin="0,0,5,0"
                                         MenuPlacement="Left"
                                         Command="{Binding IncDecCommand, Mode=OneTime}" 
                                         ItemsSource="{Binding IncDecMenu, Mode=OneTime}" />
                <ToggleButton Content="Combo" IsChecked="{Binding ComboMode, Mode=OneWay}" Command="{Binding ComboCommand, Mode=OneTime}"
                              Height="20" Width="50" Margin="0,0,5,0">
                    <ToggleButton.Style>
                        <Style TargetType="ToggleButton">
                            <Style.Triggers>
                                <Trigger Property="IsChecked" Value="True">
                                    <Setter Property="Template">
                                        <Setter.Value>
                                            <ControlTemplate TargetType="ToggleButton">
                                                <Border BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" Background="{TemplateBinding Background}">
                                                    <ContentPresenter HorizontalAlignment="Center" VerticalAlignment="Center" />
                                                </Border>
                                            </ControlTemplate>
                                        </Setter.Value>
                                    </Setter>
                                    <Setter Property="Background" Value="Yellow"/>
                                </Trigger>
                            </Style.Triggers>
                        </Style>
                    </ToggleButton.Style>
                </ToggleButton>
                <ToggleButton Content="Learn" IsChecked="{Binding LearnMode, Mode=OneWay}" Command="{Binding LearnCommand, Mode=OneTime}" 
                              Height="20" Width="50" Margin="0,0,5,0">
                    <ToggleButton.Style>
                        <Style TargetType="ToggleButton">
                            <Style.Triggers>
                                <Trigger Property="ToggleButton.IsChecked" Value="True">
                                    <Setter Property="Template">
                                        <Setter.Value>
                                            <ControlTemplate TargetType="ToggleButton">
                                                <Border BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" Background="{TemplateBinding Background}">
                                                    <ContentPresenter HorizontalAlignment="Center" VerticalAlignment="Center"/>
                                                </Border>
                                            </ControlTemplate>
                                        </Setter.Value>
                                    </Setter>
                                    <Setter Property="Background" Value="Red"/>
                                </Trigger>
                            </Style.Triggers>
                        </Style>
                    </ToggleButton.Style>
                </ToggleButton>
            </StackPanel>
            <Button Content="Reset" Command="{Binding ResetCommand, Mode=OneTime}" Height="20" Width="50" IsEnabled="{Binding LearnMode, Mode=OneWay, Converter={StaticResource invBoolConverter}}"/>
        </StackPanel>
    </Grid>
</UserControl>
